<?php
/**
 * Notes:
 * User: wudg <544038230@qq.com>
 * Date: 2025/3/31 12:17
 */

namespace App\Middleware;


use App\Traits\ApiResponseTrait;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Qbhy\HyperfAuth\AuthManager;
use Qbhy\SimpleJwt\Exceptions\TokenExpiredException;

class AuthenticateSSO implements MiddlewareInterface
{
    use ApiResponseTrait;


    protected $container;

    protected $auth;



    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;

        $this->auth = $container->get(AuthManager::class);
    }




    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        if ($this->auth->guard('sso')->guest()) {
            throw new TokenExpiredException("账号未授权",401);
        }
        return $handler->handle($request);
    }
}